package com.fengzai.web;

import com.alibaba.dubbo.rpc.RpcContext;
import com.fengzai.bean.Product;
import com.fengzai.bean.User;
import com.fengzai.service.ProductService;
import com.fengzai.service.UserService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * Created by  峰仔  on 2017-08-19
 */
public class UserWeb {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("user-consumer.xml");
        UserService userService = (UserService) context.getBean("userService");
        for (int i = 0; i < 10; i++) {
                userService.getUserLIst("小小峰仔");
                System.out.println("---");
                Future<List<User>> future = RpcContext.getContext().getFuture();
                List<User> lIst = future.get();
                for (User s : lIst) {
                System.out.println(s);
            }
            System.out.println("||||||||||||||||||||||||||||||||||||");
            //TimeUnit.SECONDS.sleep(1);
        }

        userService.getUser("小峰峰");
        Future<User> future2 = RpcContext.getContext().getFuture();
        User user = future2.get();
        System.out.println("*************************");
        System.out.println(user);
        System.out.println("*************************");
        System.out.println("-----------------------------------------");
        ProductService productService = (ProductService) context.getBean("productService");
        Product product = productService.getProductById("888888");
        System.out.println(product);
    }

}
